<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/**
 * Init Model
 *
 */


class Admin_location_model extends CI_Model {

	function __construct(){
		parent::__construct();


	}

	function getStates($parent_id){
	
		if($parent_id){
			$sql="select * from location where parent_id = $parent_id and status=51 ";
		}else{
			$sql="select * from location where parent_id = 0 and status=51 ";
		}
	
		$result = $this->db->query($sql)->result();
	
		if ($result){
			return $result;
		}
		else{
			return false;
		}
	}
	
	//--GET CATEGORY BY PK (SINHA)--//
	public function get($id){
		$sql="select * from location where id=$id limit 1";
		$result = $this->db->query($sql)->row();
		if($result){
			return $result;
		}else{
			return false;
		}
	}
	
	function get_cities_by_state($stateID = null){
		//echo $stateID;die;
		$this->db->select('*');
	
		if($stateID != NULL){
			$this->db->where('parent_id', $stateID);
		}
		$query = $this->db->get('location');
	
	
		$cities = array();
	
		if($query->result()){
			foreach ($query->result() as $city) {
				$cities[$city->id] = $city->name;
			}
			return $cities;
	
		}else{
			return FALSE;
		}
	
	
	}
}
//** end of Code //